package com.aipanda.pojo;

import com.aipanda.pojo.SQLSequence.Direction;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**分页类
 * @param pageNumber  		页码
 * @param pageSize  		每页显示条数
 * @param searchProperty 	搜索属性
 * @param searchValue  		搜索值
 * @param orderProperty  	排序属性
 * @param orderDirection  	排序方向
 * @param filters 			过滤条件
 * @param orders 			排序条件
 * @author wanyuxiang
 *
 */
public class Pageable implements Serializable {
	private static final long serialVersionUID = -3930180379790344299L;
	private int pageNumber = 1;
	private int pageSize = 20;
	private String searchProperty;
	private String searchValue;
	private String orderProperty;
	private Direction orderDirection;
	private List<SQLCondition> filters = new ArrayList<SQLCondition>();
	private List<SQLSequence> orders = new ArrayList<SQLSequence>();

	public Pageable() {
	}

	public Pageable(Integer pageNumber, Integer pageSize) {
		if ((pageNumber != null) && (pageNumber >= 1)) {
			this.pageNumber = pageNumber;
		}
		if ((pageSize != null) && (pageSize >= 1) && (pageSize <= 1000)) {
			this.pageSize = pageSize;
		}
	}

	public int getPageNumber() {
		return this.pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		if (pageNumber < 1) {
			this.pageNumber = 1;
		}
		this.pageNumber = pageNumber;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		if ((pageSize < 1) || (pageSize > 1000)) {
			pageSize = 20;
		}
		this.pageSize = pageSize;
	}

	public String getSearchProperty() {
		return this.searchProperty;
	}

	public void setSearchProperty(String searchProperty) {
		this.searchProperty = searchProperty;
	}

	public String getSearchValue() {
		return this.searchValue;
	}

	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}

	public String getOrderProperty() {
		return this.orderProperty;
	}

	public void setOrderProperty(String orderProperty) {
		this.orderProperty = orderProperty;
	}

	public Direction getOrderDirection() {
		return this.orderDirection;
	}

	public void setOrderDirection(Direction orderDirection) {
		this.orderDirection = orderDirection;
	}

	public List<SQLCondition> getFilters() {
		return this.filters;
	}

	public void setFilters(List<SQLCondition> filters) {
		this.filters = filters;
	}

	public List<SQLSequence> getOrders() {
		return this.orders;
	}

	public void setOrders(List<SQLSequence> orders) {
		this.orders = orders;
	}

	public boolean equals(Object obj) {
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		if (this == obj){
			return true;
		}
		Pageable pageable = (Pageable) obj;
		return new EqualsBuilder().append(getPageNumber(),pageable.getPageNumber()).append(getPageSize(),
				pageable.getPageSize()).append(getSearchProperty(),pageable.getSearchProperty()).append(getSearchValue(),
				pageable.getSearchValue()).append(getOrderProperty(),pageable.getOrderProperty()).append(getOrderDirection(),
				pageable.getOrderDirection()).append(getFilters(),pageable.getFilters()).append(getOrders(),
				pageable.getOrders()).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(getPageNumber()).append(
				getPageSize()).append(getSearchProperty()).append(getSearchValue()).append(getOrderProperty()).append(
				getOrderDirection()).append(getFilters()).append(getOrders()).toHashCode();
	}
}
